package com.lagou.hw1;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class IntegerReducer extends Reducer<IntWritable, NullWritable, Text,NullWritable> {

    Text keyOut = new Text();

    @Override
    protected void reduce(IntWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        //全局自增的id
        int id = IntegerUtils.num.getAndIncrement();
        //设置输出的值  id \t key值
        keyOut.set(id + "\t" +key.get());
        //把最终输出写入上下文
        context.write(keyOut,NullWritable.get());


    }
}
